package com.yzb.config;


import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import javax.servlet.annotation.HandlesTypes;
import java.util.Set;

//为什么要实现WebApplicationInitializer这个接口,这种是springboot规定的
//spi3.0规范则是在META-INF.services文件夹中的javax.servlet.ServletContainerInitializer文件写上需要实现类的全路径，方法中多了一个参数
//public class MyServletInit extends MyServlet implements WebApplicationInitializer {
//
//    public void onStartup(ServletContext servletContext) throws ServletException {
//        ServletRegistration.Dynamic dynamic =servletContext.addServlet("MyDispatcherServlet",super.getDispatcherServlet());
//        dynamic.setLoadOnStartup(1);
//        dynamic.addMapping("/");
//    }
//}
//spi3.0写法

@HandlesTypes({MySpringServletContainerInitializer.class})
public class MySpringServletContainerInitializer extends MyServlet  implements  ServletContainerInitializer {
    @Override
    public void onStartup(Set<Class<?>> set, ServletContext servletContext) throws ServletException {
        ServletRegistration.Dynamic dynamic =servletContext.addServlet("MyDispatcherServlet",super.getDispatcherServlet());
        dynamic.setLoadOnStartup(1);
        dynamic.addMapping("/app/*");
    }
}